package com.party.core.service.commune.impl;

import com.party.common.paging.Page;
import com.party.common.utils.LangUtils;
import com.party.core.dao.read.commune.CAdminBranchReadDao;
import com.party.core.dao.write.commune.CAdminBranchWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.commune.CAdminBranch;
import com.party.core.model.member.MemberGroup;
import com.party.core.service.commune.ICAdminBranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @program: party
 * @description: 管理员分社业务接口实现
 * @author: Hua Qunhao
 * @create: 2020-01-09 09:54
 **/
@Service("cAdminBranchService")
public class CAdminBranchService implements ICAdminBranchService {
    @Autowired
    private CAdminBranchReadDao cAdminBranchReadDao;
    @Autowired
    private CAdminBranchWriteDao cAdminBranchWriteDao;

    @Override
    public String insert(CAdminBranch cAdminBranch) {
        BaseModel.preInsert(cAdminBranch);
        boolean result = cAdminBranchWriteDao.insert(cAdminBranch);
        if (result) {
            return cAdminBranch.getId();
        }
        return null;
    }

    @Override
    public boolean update(CAdminBranch cAdminBranch) {
        cAdminBranch.setUpdateDate(new Date());
        return cAdminBranchWriteDao.update(cAdminBranch);
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        return cAdminBranchWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        return false;
    }

    @Override
    public CAdminBranch get(String id) {
        return cAdminBranchReadDao.get(id);
    }

    @Override
    public List<CAdminBranch> listPage(CAdminBranch cAdminBranch, Page page) {
        return cAdminBranchReadDao.listPage(cAdminBranch,page);
    }

    @Override
    public List<CAdminBranch> list(CAdminBranch cAdminBranch) {
        return cAdminBranchReadDao.listPage(cAdminBranch,null);
    }

    @Override
    public List<CAdminBranch> batchList(Set<String> ids, CAdminBranch cAdminBranch, Page page) {
        return null;
    }

    @Override
    public List<String> getBranchIdsByAdminId(String adminId) {
        CAdminBranch cAdminBranch = new CAdminBranch();
        cAdminBranch.setAdminId(adminId);
        List<CAdminBranch> list = this.list(cAdminBranch);
        List<String> memberGroupIds = LangUtils.transform(list, input -> input.getBranchId());
        return memberGroupIds;
    }
}
